{include file="common/_header"}
{include file="common/_header1"}

<body class="layui-anim layui-anim-up">
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">审核管理</a>
            <a>
              <cite>商品审核管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">

    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
                <div class="layui-unselect layui-form-select spf_id" style="display:inline-block;">
                    <select name="class_id" lay-filter="class_id" class="select_subplat">
                        <option value="">请选择类型</option>
                        {volist name="data.classlist" id="vo"}
                        <option value={$key} {$data.get.class_id == $key?'selected':''}>{$vo}</option>
                        {/volist}
                    </select>
                </div>
                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>

        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="delAll()">一键通过</button>
        <!--        <button class="layui-btn" onclick="x_admin_show('添加商品','/products/boxeproduct?product_id=0',800,600)"><i class="layui-icon"></i>  添 加</button>-->
        <!--            <span class="x-right" style="line-height:40px">共有数据：88 条</span>-->
    </xblock>


    <table id="tables" class="layui-table layui-form">
        <thead>
        <tr>
            <th style="text-align: center"><input type="checkbox" lay-filter="checkall" name="" lay-skin="primary"></th>
            <th>商铺名称</th>
            <th>类型</th>
            <th>商品名称</th>
            <th>商品图片</th>
            <th>商品类型</th>
            <th>原价</th>
            <th>销售价格</th>
            <th>会员价格</th>
            <th>邮费</th>
            <th>兑换积分</th>
            <th>审核状态</th>
            <th>审核意见</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data.data" id="vo"}
        <tr class="table_tr">
            <td><input type="checkbox" name="id" value="{$vo.product_id}" lay-skin="primary"></td>
            <td>{$vo.shop_id == 0?'总部':$vo.shop_name}</td>
            <td>{$vo.product_name}</td>
            <td>{$data.classlist[$vo.class_id]}</td>
            <td><img src="/{$vo.imageurl}"></td>
            <td>{$vo.type_name}</td>
            <td>{$vo.price}</td>
            <td>{$vo.sprice}</td>
            <td>{$vo.mprice}</td>
            <td>{$vo.express_fee}</td>
            <td>{$vo.integral}</td>
            <td>{$vo.approved == 1?'待审核':$vo.approved == 2?'审核通过':'审核失败'}</td>
            <td>{$vo.reasons}</td>
            <td>{$vo.createat|date="Y-m-d H:i:s"}</td>
            <td>
                <ul class="nav navbar-nav" style=" height: 40px; line-height: 10px;">
                    <li class="dropdown" style="height: 100%;">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                           style=" height: 100%; line-height: 5px;">
                            操作
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a title="商品信息"
                                   onclick="x_admin_show('商品信息', '/trial/productinfo?product_id={$vo.product_id}', '800', '600')"
                                   href="javascript:;">商品信息</a></li>
                            <li class="divider"></li>
                            <li><a title="审核不通过"
                                   onclick="x_admin_show('审核不通过', '/trial/failproduct?product_id={$vo.product_id}', '800', '400')"
                                   href="javascript:;">审核不通过</a></li>

                        </ul>
                    </li>
                </ul>
            </td>

        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page_all">
        {$page|raw}
    </div>
</div>
<script>

    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;

        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });


    // 批量审核
    function delAll() {

        var ids = [];

        // 获取选中的id
        $('tbody input').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });

        layer.confirm('您确定选中的商品一致通过？', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'adoptproducts?ids=' + ids,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });

    }


    $(function () {
        // 表格选中行的同时选中单选框
        $("#tables tr:gt(0)").click(function () {
            $(this).find(":radio").prop("checked", true);
        });

    });

    //js放到table下，才能检测到tr数组
    var trs = document.getElementById("tables").getElementsByTagName("tr");
    $(function () {
        for (var i = 0; i < trs.length; i++) {
            trs[i].onmousedown = function () {
                mousedownclick(this);
            }
        }
    });

    function mousedownclick(obj) {
        for (var j = 0; j < trs.length; j++) {
            if (trs[j] == obj) {
                if (trs[0] != obj) {
                    trs[j].style.background = '#D0E9C6';
                    // 启用新增和编辑按钮
                    $("#edits").removeAttr("disabled");//启用按钮
                    $('#edits').removeClass('layui-disabled');
                }
            } else {
                trs[j].style.background = '';
            }
        }
    }


    function opreate(id) {
        layer.confirm('您确定要删除该商品吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'delproduct?productid=' + id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });
    }
</script>
</body>


{include file="common/_bottom"}